home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime for java / slideshow / src / viewerdemo.java < prev   
Encoding:
Java Source  |  2000-06-23  |  2.0 KB  |  74 lines

  1. /*
  2.  * QuickTime for Java SDK Sample Code
  3.  
  4.    Usage subject to restrictions in SDK License Agreement
  5.  * Copyright: © 1996-1999 Apple Computer, Inc.
  6.  
  7.  */
  8. import java.awt.*;
  9. import java.awt.event.*;
  10. import java.io.*;
  11.  
  12. import quicktime.*;
  13. import quicktime.util.*;
  14. import quicktime.app.QTFactory;
  15. import quicktime.app.display.*;
  16. import quicktime.app.image.*;
  17. import quicktime.qd.*;
  18.  
  19. /*
  20.  This demo shows a simple slide show presentation where the SlideShow object defines
  21.  the behaviour that moves the currently viewed image to the next or previous image
  22.  based on mousePressed events.
  23. */
  24. public class ViewerDemo extends Frame {
  25.     public static void main (String[] args) {
  26.         ViewerDemo vd = new ViewerDemo();
  27.         vd.init();
  28.         vd.show();
  29.         vd.toFront();
  30.     }
  31. //____________________ INSTANCE METHODS
  32.  
  33.     public void init () {
  34. // The frame, canvas and viewer are all the same size
  35.         try {
  36.             QTSession.open();
  37.  
  38. // add canvas to frame
  39.             setLayout (new BorderLayout());
  40.             QTCanvas canv = new QTCanvas ();
  41.             add ("Center", canv);
  42.             
  43. // create image sequence        
  44.             File file = QTFactory.findAbsolutePath ("images/Ship01.pct");        
  45.             ImageDataSequence seq = ImageUtil.createSequence (file);
  46.             ImageSequencer images = new ImageSequencer (seq);
  47.             images.setLooping (ImageSequencer.kLoopForwards);        
  48.  
  49. // create our SlideShow
  50.             SlideShow viewer = new SlideShow (images);
  51.  
  52.             addNotify();    //required so we can set the frame to the right size for insets
  53.             Insets insets = getInsets();
  54.             Dimension d = new Dimension (viewer.getDisplayBounds().getWidth(), viewer.getDisplayBounds().getHeight());
  55.             setSize ((insets.left + insets.right + d.width), (insets.top + insets.bottom + d.height));
  56.  
  57.             addWindowListener(new WindowAdapter () {
  58.                 public void windowClosing (WindowEvent e) {
  59.                     QTSession.close();
  60.                     dispose();
  61.                 }
  62.                 public void windowClosed (WindowEvent e) {
  63.                     System.exit(0);
  64.                 }
  65.             });
  66.             canv.setClient (viewer, true);
  67.         } catch (Exception e) {
  68.             e.printStackTrace();
  69.             QTSession.close();
  70.         }    
  71.     }
  72. }
  73.  
  74.